package Client;

import java.io.BufferedReader;
import java.io.IOException;

/**
 * Listens for messages from the Sockets BufferedReader and forwards them to
 * ClientSocket class.
 * 
 * @author PZK
 * 
 */
public class Listener extends Thread {

	private ClientSocket clientSocket;
	private BufferedReader in;

	public Listener(ClientSocket clientSocket, BufferedReader in) {

		this.clientSocket = clientSocket;
		this.in = in;

		start();

	}

	@Override
	public void run() {

		try {
			String message;
			while ((message = in.readLine()) != null) {
				clientSocket.messageReceived(message);
			}
		} catch (IOException e) {
			// connection interrupted
		}
		
		clientSocket.disconnect();

	}

}
